{% include 'admin/header.html' %}
<script type="text/javascript">
	changeTab('管理员信息');
	$(function () {
        $('.search').on('submit', function (e) {
            e.preventDefault();
            if ($(this).find('input').val() !== '') {
                var tbody = $('.table tbody');
                $.post('/admin/search', $(this).serialize(), function (data) {
                    console.log(data)
                    if (data.status) {
                        var v = data.result;
                        tbody.html('');
                        tbody.append('<tr>\n' +
                            '\t\t\t\t\t\t\t\t<td>1</td>\n' +
                            '\t\t\t\t\t\t\t\t<td>'+v.ad_name+'</td>\n' +
                            '\t\t\t\t\t\t\t\t<td>'+v.teacher_name+'</td>\n' +
                            '\t\t\t\t\t\t\t\t<td>'+v.ad_tel+'</td>\n' +
                            '                                <td>'+v.end_time+'</td>\n' +
                            '\t\t\t\t\t\t\t\t<td>\n' +
                            '\t\t\t\t\t\t\t\t\t<button onclick="adminDelete('+v.id+')" class="btn btn-xs btn-danger">删除</button>\n' +
                            '\t\t\t\t\t\t\t\t</td>\n' +
                            '\t\t\t\t\t\t\t</tr>');
                    } else {
                        tbody.html('<tr><td align="center" colspan="5">无该记录</td></tr>');
                    }
                });
            }
        });
    });

	function gotoPage(e, page) {
		var pages = {{ a_page.pages }};
		var status = $(e).parent().attr("class");
		if (page > 0 && page <= pages && page !== {{ a_page.page }} &&
            status !== "active") {
			location.href = '/admin/list?page='+page;
		}
	}

	function adminDelete(id, ad_name) {
	    var flag = confirm('确定要删除<' + ad_name + '>吗？');
	    if (flag) {
            $.post("/admin/delete", {id: id}, function (data) {
                if (data.status) {
                    alert("SUCCESS: 删除成功！");
                    location.reload();
                } else {
                    alert("ERROR: " + data.msg);
                    location.reload();
                }
            });
        }
	}
</script>
<div class="work-xcontent">
	<div>
		<div class="col-lg-12 col-xs-12">
			<a class="text-black" href=""><h4><span class="fa fa-hand-o-right"></span> 管理员信息</h4></a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <a href="/admin/add" class="btn btn-warning btn-sm">添加</a>
				<form class="search pull-right">
                    <div class="input-group min-input">
                        <input name="username" style="height: 30px;" class="form-control" type="text" placeholder="账号">
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-default btn-sm">
                                <span class="fa fa-search"></span>
                            </button>
                        </span>
                    </div>
                </form>
			</div>
		</div>
        <div>
			<div class="col-lg-12 col-xs-12">
				<table class="table table-striped">
					<thead class="bg-color-x">
						<tr>
							<td>索引</td>
							<td>账号</td>
                            <td>名字</td>
							<td>电话</td>
							<td>最后登录</td>
							<td>操作</td>
						</tr>
					</thead>
					<tbody>
                        {% if a_page.total <= 0 %}
							<tr>
                                <td align="center" colspan="5">
                                    暂无数据  <a class="red-a" href="">快去添加</a>
                                </td>
                            </tr>
                        {% else %}
                            {% for a in a_page.result %}
							<tr>
								<td>{{ loop.index }}</td>
								<td>{{ a.ad_name }}</td>
                                <td>{{ a.teacher_name }}</td>
								<td>{{ a.ad_tel }}</td>
                                <td>{{ a.end_time }}</td>
								<td>
									<button onclick="adminDelete({{ a.id }}, '{{ a.ad_name }}')" class="btn btn-xs btn-danger">删除</button>
								</td>
							</tr>
                            {% endfor %}
                        {% endif %}
					</tbody>
				</table>
				<!-- 分页按钮 -->
                {% if a_page.pages > 1 %}
                    <div class="col-lg-12 col-xs-12 text-center">
                        <ul style="margin: 0;" class="pagination pagination-sm">
                            <li onclick="gotoPage(this, 1)"><a href="javascript:">首页</a></li>
                            <li onclick="gotoPage(this, {{ a_page.page - 1 }})"><a href="javascript:">&laquo;</a></li>
                            {% for foo in range(a_page.pages) %}
                                <li onclick="gotoPage(this, {{ foo + 1 }})" class="{% if foo == a_page.page - 1 %}active{% endif %}">
                                    <a href="javascript:">{{ foo + 1 }}</a>
                                </li>
                            {% endfor %}
                            <li onclick="gotoPage(this, {{ a_page.page + 1 }})"><a href="javascript:">&raquo;</a></li>
                            <li onclick="gotoPage(this, {{ a_page.pages }})"><a href="javascript:">尾页</a></li>
                        </ul>
                        <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
                            共{{ a_page.pages }}页，{{ a_page.total }}条数据
                        </span>
                    </div>
                {% endif %}
			</div>
		</div>
    </div>
</div>

{% include 'admin/footer.html' %}